//
//  ActionSheet.m
//  mhome
//
//  Created by YaSha_Tom on 2018/12/4.
//  Copyright © 2018年 刘春雷. All rights reserved.
//

#import "ActionSheet.h"

@implementation ActionSheet

-(id)initViewWithMultiPhone:(NSArray *)array title:(NSString *)title{
    
    if (self = [self init]) {
        _actionSheet.title = title;
        NSLog(@"===========%@",array);
        for (NSString *phone in array) {
            [_actionSheet addButtonWithTitle:phone];
        }
    }
    return self;
}

-(id)init{
    CGRect bounds = [[UIScreen mainScreen] bounds];
    if (self = [super initWithFrame:bounds]) {
        self.backgroundColor = [UIColor clearColor];
        
        _actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
        
        _actionSheet.cancelButtonIndex = [_actionSheet addButtonWithTitle:@"取消"];
    }
    return self;
}
- (void)show{
    [_actionSheet showInView : self];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == actionSheet.cancelButtonIndex) {
        [self close];
    }else{
        [self onPhoneButtonClick:[_actionSheet buttonTitleAtIndex:buttonIndex]];
    }
}
- (void)onPhoneButtonClick:(NSString *)phone {
    self.black(phone);//调⽤用block⽅方法
    self.phone = phone;
    NSLog(@"%@",phone);
    [self close];
    
}

- (void)close{
   [self removeFromSuperview];
}

@end
